package com.example.phone.base;

import com.example.phone.base.ServerResponse;
import com.example.phone.bean.AddressList;
import com.example.phone.bean.Category;
import com.example.phone.bean.MyPageInfo;
import com.example.phone.bean.Orders;
import com.example.phone.bean.ParentCategory;
import com.example.phone.bean.Product;
import com.example.phone.bean.SearchResult;
import com.example.phone.bean.ShoppingCart;
import com.example.phone.bean.ShoppingCartList;
import com.example.phone.bean.User;

import java.util.List;
import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;

/**
 * Created by Administrator on 2018\12\24 0024.
 */

public class RequestInterface {
    /**
     * 后台url ip地址
     */
    public static final String baseIp = "120.77.253.51";
    /**
     * 后台url地址
     */
    public static final String basePath = "http://" + baseIp + ":8080/PhoneShop/";


    public static final String baseImgPath = "http://" + baseIp + ":8080/PhoneShop/Images/";

    //登陆接口，使用Gson解析，也是请求单个数据的示例
    public interface Login3 {
        @POST("user/login")
        @FormUrlEncoded
        Call<ServerResponse<User>> login(@Field("username") String userName, @Field("password") String password);
    }

    //以原生方式获取返回结果，不用Gson解析（在Gson解析出错的情况下，获取返回的数据进行操作（看是哪一项数据解析不了，已知Date类型不行））
    public interface Login2 {
        @POST("login.do")
        @FormUrlEncoded
        Call<ResponseBody> login(@Field("username") String userName, @Field("password") String password);
    }

    //登录状态更新个人信息接口
    public interface UpdateUserInfo {
        @POST("user/update_information.do")
        @FormUrlEncoded
        Call<ServerResponse<User>> update(@Field("email") String email, @Field("phone") String phone, @Field("question") String question, @Field("answer") String answer);
    }

    //忘记密码
    public interface ForgetPassword {
        @POST("user/forget_get_question.do")
        @FormUrlEncoded
        Call<ResponseBody> findBack(@Field("username") String username);
    }

    //登录状态更新个人信息接口(因为返回值不是一个对象，那么不用解析)
    public interface Register {
        @POST("user/register.do")
        @FormUrlEncoded
        Call<ServerResponse> register(@Field("username") String userName,
                                      @Field("password") String password,
                                      @Field("email") String email,
                                      @Field("phone") String phone);
    }

    //登录状态更新个人信息接口(尝试解析)
    public interface Register2 {
        @POST("user/register.do")
        @FormUrlEncoded
        Call<ServerResponse> register2(@Field("username") String userName, @Field("password") String password, @Field("email") String email, @Field("phone") String phone, @Field("question") String question, @Field("answer") String answer);
    }





    public interface getProductsList {
        @POST("product/list.do")
        @FormUrlEncoded
        Call<ServerResponse<Product>> getProducts(@FieldMap Map<String, String> params);
    }

    //请求数据集合的接口，使用Gson解析，其中ServerResponse<T>中的T保持和后台Controller中对应的方法保持一致
    public interface getProductsList2 {
        @POST("product/list.do")
        @FormUrlEncoded
        Call<ServerResponse<MyPageInfo<Product>>> getProducts(@Field("pageNum") int pageNum,
                                                              @Field("pageSize") int pageSize,
                                                              @Field("orderBy") String orderBy);
    }

    //新的
    //根据产品Id来获取商品详情
    public interface getProductDetail{
        @POST("product/detail")
        @FormUrlEncoded
        Call<ServerResponse<Product>> getProductDetail(@Field("productId") Integer productId);
    }


    //登录状态更新个人信息接口(尝试解析)
   public interface Address {
        @POST("shipping/add")
        @FormUrlEncoded
        Call<ServerResponse> add(@Field("userId") int userId,
                                 @Field("receiverName") String receiverName,
                                 @Field("receiverPhone") String receiverPhone,
                                 @Field("receiverMobile") String receiverMobile,
                                 @Field("receiverProvince") String receiverProvince,
                                 @Field("receiverCity") String receiverCity,
                                 @Field("receiverAddress") String receiverAddress,
                                 @Field("receiverZip") String receiverZip
        );

        @POST("shipping/list")
        @FormUrlEncoded
        Call<ServerResponse<MyPageInfo>> getAddressList(@Field("pageNum") int pageNum,
                                                        @Field("pageSize") int pageSize);

    }

    public interface Cart {
        //购物车List列表
        @POST("cart/list")
        @FormUrlEncoded
        Call<ServerResponse> getShippingList();

        //新的
        //购物车添加商品
        @POST("cart/add")
        @FormUrlEncoded
        Call<ServerResponse> add(@Field("productId") int productId,
                                                   @Field("count") int count,
                                                   @Field("userId") int userId );

        //更新购物车商品数量
        @POST("cart/update")
        @FormUrlEncoded
        Call<ServerResponse> update(@Field("productId") int productId,
                                    @Field("count") int count);
        //删除购物车商品
        @POST("cart/delete_product")
        @FormUrlEncoded
        Call<ServerResponse> delete(@Field("productId") int productId,
                                    @Field("count") int count);
    }

    //产品分类
    public interface getParentCategory {
        @POST("manage/category/get_parentCategory_list")
        @FormUrlEncoded
        Call<ServerResponse<List<ParentCategory>>> getParentCategorys(@Field("id") String categoryId,
                                                                      @Field("name") String categoryName);
    }

    //分类产品
    public interface getCategorpyProducts {
        @POST("manage/category/get_category_by_parent")
        @FormUrlEncoded
        Call<ServerResponse<List<Category>>> getCategoryProducts(@Field("parentId") Integer parentId);
    }

    //商品详情
    public interface getProductDetails {
        @POST("manage/product/detail")
        @FormUrlEncoded
        Call<ServerResponse<Product>> getCategoryProducts(@Field("productId") Integer productId);
    }


    public interface CartRequest {
        @GET("cart/list?")
        Call<ServerResponse<ShoppingCartList>> getShoppingCartList(@Query("userId") Integer userId);

        @GET("cart/update?")
        Call<ServerResponse<ShoppingCartList>> updateShoppingCartList(@Query("userId") Integer userId,
                                                                      @Query("productId") Integer productId,
                                                                      @Query("count") Integer count);

        @GET("cart/delete_product?")
        Call<ServerResponse<ShoppingCartList>> deleteShoppingCartList(@Query("userId") Integer userId, @Query("productId") Integer productId);
    }

    public interface SearchRequest {
        @GET("product/list?")
        Call<ServerResponse<MyPageInfo<SearchResult>>> getProductList(@Query("keyword") String keyword,
                                                                      @Query("pageNum") int pageNum,
                                                                      @Query("pageSize") int pageSize);
    }

    /**
     * 地址管理
     */
    public interface ManageAddress {

        /**
         * 查询地址列表
         * @param id
         * @return
         */
        @GET("manage/shipping/list?")
        Call<ServerResponse<AddressList>> getAddrssList(@Query("userId") int id);

        /**
         * 更新地址
         * @param id
         * @return
         */
        @POST("manage/shipping/update")
        @FormUrlEncoded
        Call<ServerResponse> updateAddress(@Field("shippingId") int id, @Field("name") String name,
                                           @Field("mobile")String mobile, @Field("province")String province,
                                           @Field("city")String city, @Field("address")String address);

        /**
         * 地址更新
         * @param id 用户ID
         * @param name 接收者名称
         * @param mobile 接收者手机号
         * @param province 省份
         * @param city 城市
         * @param address 地址
         * @return
         */
        @POST("manage/shipping/add")
        @FormUrlEncoded
        Call<ServerResponse> addAddress(@Field("userId") int id, @Field("name") String name,
                                        @Field("mobile")String mobile, @Field("province")String province,
                                        @Field("city")String city, @Field("address")String address);


    }

    public interface OrderDao {
        @POST("order/list")
        @FormUrlEncoded
        Call<ServerResponse<Orders>> searchOrder(@Field("userId") int id);
    }

}
